/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package kivuli.visao.dialog;

import kivuli.entidade.Arvore;
import kivuli.visao.FramePrincipal;

/**
 *
 * @author bpmlab
 */
public class DialogArvore extends javax.swing.JDialog {

    private final Arvore arvore;
    private boolean ok = false;

    public DialogArvore(FramePrincipal framePrincipal, Arvore arvore) {
        super(framePrincipal, true);
        this.arvore = arvore;
        initComponents();
        valoresPadrao();
        this.setLocationRelativeTo(null);
        this.setVisible(true);
    }

    private void valoresPadrao() {
        if (arvore != null) {
            txAlturaCopa.setText(arvore.getAlturaCopa() + "");
            txAlturaTronco.setText(arvore.getAlturaTronco() + "");
            txDiametroCopa.setText(arvore.getDiametroCopa() + "");
            txDiametroTronco.setText(arvore.getDiametroTronco() + "");
        }
    }

    public boolean isOk() {
        return ok;
    }

    public Arvore getArvore() {
        return arvore;
    }
    
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lbAlturaTronco = new javax.swing.JLabel();
        lbDiametroTronco = new javax.swing.JLabel();
        lbAlturaCopa = new javax.swing.JLabel();
        lbDiamentroCopa = new javax.swing.JLabel();
        txAlturaTronco = new javax.swing.JTextField();
        txDiametroTronco = new javax.swing.JTextField();
        txAlturaCopa = new javax.swing.JTextField();
        txDiametroCopa = new javax.swing.JTextField();
        btnOk = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Configurar Árvore");
        setResizable(false);

        lbAlturaTronco.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbAlturaTronco.setText("Altura Tronco: ");

        lbDiametroTronco.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbDiametroTronco.setText("Diâmetro Tronco: ");

        lbAlturaCopa.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbAlturaCopa.setText("Altura Copa: ");

        lbDiamentroCopa.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        lbDiamentroCopa.setText("Diâmentro Copa: ");

        txAlturaTronco.setCursor(new java.awt.Cursor(java.awt.Cursor.TEXT_CURSOR));

        btnOk.setText("Ok");
        btnOk.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnOkActionPerformed(evt);
            }
        });

        btnCancelar.setText("Cancelar");
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(lbAlturaCopa, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGap(5, 5, 5))
                    .addComponent(lbAlturaTronco, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbDiametroTronco, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(lbDiamentroCopa, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(txAlturaTronco, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE)
                    .addComponent(txDiametroTronco)
                    .addComponent(txAlturaCopa)
                    .addComponent(txDiametroCopa))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnCancelar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnOk)
                .addGap(21, 21, 21))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbAlturaTronco)
                    .addComponent(txAlturaTronco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDiametroTronco)
                    .addComponent(txDiametroTronco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbAlturaCopa)
                    .addComponent(txAlturaCopa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbDiamentroCopa)
                    .addComponent(txDiametroCopa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnOk)
                    .addComponent(btnCancelar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnOkActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOkActionPerformed
        int alturaCopa = Integer.parseInt(txAlturaCopa.getText());
        int alturaTronco = Integer.parseInt(txAlturaTronco.getText());
        int diametroCopa = Integer.parseInt(txDiametroCopa.getText());
        int diametroTronco = Integer.parseInt(txDiametroTronco.getText());

        arvore.setAlturaCopa(alturaCopa);
        arvore.setAlturaTronco(alturaTronco);
        arvore.setDiametroCopa(diametroCopa);
        arvore.setDiametroTronco(diametroTronco);

        this.dispose();
        ok = true;
    }//GEN-LAST:event_btnOkActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnOk;
    private javax.swing.JLabel lbAlturaCopa;
    private javax.swing.JLabel lbAlturaTronco;
    private javax.swing.JLabel lbDiamentroCopa;
    private javax.swing.JLabel lbDiametroTronco;
    private javax.swing.JTextField txAlturaCopa;
    private javax.swing.JTextField txAlturaTronco;
    private javax.swing.JTextField txDiametroCopa;
    private javax.swing.JTextField txDiametroTronco;
    // End of variables declaration//GEN-END:variables
}
